using Quartz.AspNetCore;
using Quartz;
using WeskyQuantDemo;
using WeskyQuantDemo.Services;
using CrystalQuartz.AspNetCore;
using WeskyQuantDemo.Models.Quartz;
using WeskyQuantDemo.HostServices;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHttpClient();

builder.Services.AddQuartz();
builder.Services.AddQuartzServer(options =>
{
    options.WaitForJobsToComplete = true;
});
builder.Services.AddScoped<IQuantDataService, QuantDataService>();
builder.Services.AddSingleton<IHostedService, QuartzJobInitHostService>();

Global.GlobalServiceProvider = builder.Services.BuildServiceProvider();


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseCrystalQuartz(() => { return JobSchedulerInfo.JobsScheduler; });


app.UseAuthorization();

app.MapControllers();

app.Run();
